/*
 * anima/pc/console.cc - Console functions for PC platform.
 * Copyright (C) 2007  Mikhail Vorozhtsov
 * See the LICENSE section of the README file for details.
 */

/* $Id$ */

#include HEADER (anima,console.hh)
#include PLATFORM_HEADER (console-vga.hh)
#include PLATFORM_HEADER (console-serial.hh)

START_NAMESPACE2 (anima,pc)

static const char *console_type = NULL;

const ::anima::cmdline::option_t console::console_type_option
  = ::anima::cmdline::option_t (
      "console", NULL, (const char *[]) { "vga", "serial" }, &console_type);

static const char *console_serial_port = NULL;

const ::anima::cmdline::option_t console::console_serial_port_option
  = ::anima::cmdline::option_t (
      "console:serial:port", NULL,
      (const char *[]) { "com1", "com2", "com3", "com4" },
      &console_serial_port);

static const char *console_serial_baud_rate = NULL;

const ::anima::cmdline::option_t console::console_serial_baud_rate_option
  = ::anima::cmdline::option_t (
      "console:serial:baud_rate", NULL,
      (const char *[]) { "2400", "9600" },
      &console_serial_baud_rate);

static void (*real_putc) (char c);
static void *vga_video_mem;

bool
console::vga_console_p ()
{
  return console_type == NULL || console_type[0] == 'v';
}

void *
console::get_vga_video_mem ()
{
  return vga_video_mem;
}

void
console::set_vga_video_mem (void *video_mem)
{
  if (vga_console_p ())
    {
      vga_video_mem = video_mem;
      ::pc::vga_console::init (video_mem);
    }
}

END_NAMESPACE2

START_NAMESPACE (anima)

void
console::init ()
{
  if (vga_console_p ())
    {
      pc::vga_video_mem = (void *) 0xB8000;
      ::pc::vga_console::init (pc::vga_video_mem);
      pc::real_putc = ::pc::vga_console::putc;
    }
  else
    {
      ::pc::serial_console::init ();
      pc::real_putc = ::pc::serial_console::putc;
    }
}

void
console::putc (char c)
{
  pc::real_putc (c);
}

END_NAMESPACE

